package com.smart.daotest;

import com.smart.dao.CalenderAdao;
import com.smart.dao.ComputerRoomDao;
import com.smart.domain.CalenderA;
import com.smart.domain.ComputerRoom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
import org.springframework.transaction.annotation.Transactional;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@ContextConfiguration("classpath*:/Room-context.xml")

@Rollback(false)

public class Testone extends AbstractTransactionalTestNGSpringContextTests {

    @Autowired
    private ComputerRoomDao computerroomDao;

    @Autowired
    private CalenderAdao calenderAdao;

    @Test
    public void testdao() {
        ComputerRoom cp = new ComputerRoom();
        cp.setRoom_id(138);
        cp.setRoom_name("机房9");
        cp.setRoom_zone("南苑");
        cp.setRoom_buildingnumber(8);
        cp.setRoom_floor(5);
        cp.setRoom_roomnumber(608);
        cp.setRoom_seat(60);
        computerroomDao.addCompRoom(cp);
        System.out.println(cp.getRoom_name());
    }

    @Test
    public void testdaoupdate() {
        ComputerRoom computerRoom2 = new ComputerRoom();
        computerRoom2.setRoom_floor(9);
        computerRoom2.setRoom_buildingnumber(4);
        int a = computerroomDao.updateCompRoom(computerRoom2);
        if (a > 0) {
            System.out.print("修改成功");
        } else {
            System.out.print("修改失败");
        }
    }

    @Test
    public void testdeletedao() {
        ComputerRoom computerRoom = new ComputerRoom();
        computerRoom.setRoom_name("机房一");
        int a = computerroomDao.deleteCompRoom(computerRoom);
        System.out.println(a);
    }


    @Test
    public void testquery() {
        ComputerRoom com = new ComputerRoom();
        com.setRoom_name("机房二");
        computerroomDao.queryCompRoom(com);
    }

    @Test
    public void testquerylist() {
        ComputerRoom com = new ComputerRoom();
        computerroomDao.querylistCompRoom(com);
    }

    @Test
    public void testaddcal(){
        CalenderA calenderA =new CalenderA();
        Date date1 =new Date(118,2,7);
        Date date2 =new Date(118,6,7);
        calenderA.setTerm(2);
        calenderA.setWeek(19);
        calenderA.setStartday(date1);
        calenderA.setStopday(date2);
        calenderAdao.addCalen(calenderA);
    }

    @Test
    public void testupdatecal(){

        CalenderA calenderA =new CalenderA();
        calenderA.setTerm(1);
        calenderA.setWeek(18);
        Date date1 =new Date(116,9,03);
        Date date2 =new Date(117,2,26);

        calenderA.setStartday(date1);
        calenderA.setStopday(date2);
        calenderAdao.updateCalen(calenderA);
    }

}
